package bbchess.util;


import java.applet.AudioClip;
import java.net.URL;

/*
 * A utility class to import and play sound effects
 */
public final class SoundLoader {
    
    private static AudioClip dropClip;
    private static AudioClip chatMessageClip;
    private static AudioClip newGameClip;
    
    /** Constructor set to private to prevent instantisation */
    private SoundLoader() {
    }

    public static void loadSounds() {
        try {
            URL dropClipUrl  = SoundLoader.class.getResource("sounds/drop.wav");
            dropClip = java.applet.Applet.newAudioClip(dropClipUrl);

            URL chatMessageClipUrl = SoundLoader.class.getResource("sounds/chatmessage.wav");
            chatMessageClip = java.applet.Applet.newAudioClip(chatMessageClipUrl);

            URL newGameClipURL = SoundLoader.class.getResource("sounds/chimes.wav");
            newGameClip = java.applet.Applet.newAudioClip(newGameClipURL);
            
        } catch (Exception e) {
            System.out.println("Unable to load sound effects.");
        }
    }
    
    /**
     * Plays the drop clip
     */
    public static void drop() {
        if (dropClip != null) {
            dropClip.play();
        }
    }
    
    /**
     * Plays the chat message clip
     */
    public static void chatMessage() {
        if (chatMessageClip != null) {
            chatMessageClip.play();
        }
    }

    /**
     * Plays the new game clip
     */
    public static void newGame() {
        if (newGameClip != null) {
            newGameClip.play();
        }
    }
    
    /**
     * Stops current clips
     */
    public static void stop() {
        if (dropClip != null) {
            dropClip.stop();
        }

        if (chatMessageClip != null) {
            chatMessageClip.stop();
        }

        if (newGameClip != null) {
            newGameClip.stop();
        }
    }
}
